﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCLookUpDiaChi.ascx.cs"
    Inherits="Viewer.ToChuc.UserControls.UCLookUpDiaChi" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/ToChuc/UserControl/UCDiaChi.ascx" TagName="UCDiaChi" TagPrefix="uc" %>
<link href="../../resources/css/main.css" rel="stylesheet" type="text/css" />
<ext:XScript ID="XScipt1" runat="server">
    <script type="text/javascript">
        function ConfirmDeleteDiaChi(id) {
            Ext.MessageBox.confirm('Thông báo', 'Bạn có chắc chắn xóa record này ko?', function doDel2(btn) {
                if (btn == 'yes') {
                 Ext.net.Mask.show();
                    #{DirectMethods}.DialogDiaChi('Delete',id);
                }
            });
        }
        function Reset()
        {
            #{txtSoNha}.value='';
            #{txtThonPho}.value='';
            #{cbbTinh}.value='';
            #{cbbQuan}.value='';
            #{cbbXa}.value='';
        }
    </script>
</ext:XScript>
<ext:Window ID="wdDiaChi" runat="server" Width="800" AutoHeight="true" Modal="true"
    Closable="false" Hidden="true" HideBorders="True" Border="false" Plain="true"
    Resizable="false" Frame="false" Title="Tìm Địa chỉ" Icon="Find">
    <Content>
        <ext:Panel ID="pnlSearch" runat="server" StyleSpec="background-color:#ccd9e8;">
            <Items>
                <ext:CompositeField runat="server" StyleSpec="background-color:#ccd9e8;">
                    <Items>
                        <ext:TextField ID="txtSoNha" runat="server" EmptyText="Điền số nhà vào">
                        </ext:TextField>
                        <ext:TextField ID="txtThonPho" runat="server" EmptyText="Điền thôn phố vào">
                        </ext:TextField>
                        <ext:ComboBox ID="cbbTinh" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                            Width="160" EmptyText="Chọn Tỉnh/Thành Phố">
                            <Store>
                                <ext:Store ID="storeTinh" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                            <Fields>
                                                <ext:RecordField Name="TenToChucHanhChinh" />
                                                <ext:RecordField Name="ToChucHanhChinhID" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                            </Triggers>
                            <Listeners>
                                <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Quan');this.triggers[0].show();" />
                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                            </Listeners>
                        </ext:ComboBox>
                        <ext:ComboBox ID="cbbQuan" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                            Width="160" EmptyText="Chọn Quận/Huyện">
                            <Store>
                                <ext:Store ID="storeQuan" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                            <Fields>
                                                <ext:RecordField Name="TenToChucHanhChinh" />
                                                <ext:RecordField Name="ToChucHanhChinhID" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                            </Triggers>
                            <Listeners>
                                <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Xa');this.triggers[0].show();" />
                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                            </Listeners>
                        </ext:ComboBox>
                        <ext:ComboBox ID="cbbXa" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                            Width="175" EmptyText="Chọn xã">
                            <Store>
                                <ext:Store ID="storeXa" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                            <Fields>
                                                <ext:RecordField Name="TenToChucHanhChinh" />
                                                <ext:RecordField Name="ToChucHanhChinhID" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                            </Triggers>
                            <Listeners>
                                <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Thon');this.triggers[0].show();" />
                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                            </Listeners>
                        </ext:ComboBox>
                    </Items>
                </ext:CompositeField>
            </Items>
            <Buttons>
                <ext:Button ID="Button2" runat="server" Text="Reset">
                 <Listeners>
<Click Handler=" Ext.net.Mask.show();" /></Listeners>

                    <DirectEvents>
                        <Click OnEvent="BtnReset_Click">
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="btnSearch" runat="server" Text="Tìm kiếm" Icon="Zoom">
                 <Listeners>
<Click Handler=" Ext.net.Mask.show();" /></Listeners>

                    <DirectEvents>
                        <Click OnEvent="BtnSearch_Click">
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="btnAddNewDiachi" runat="server" Text="Tạo mới" Icon="Add">
                    <Listeners>
                        <Click Handler="Ext.net.Mask.show();#{DirectMethods}.DialogDiaChi('AddNew',0);" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Panel>
        <ext:Panel runat="server" ID="asd" Layout="Fit" MonitorResize="true">
            <Items>
                <ext:GridPanel ID="grdDiaChi" runat="server" Height="300" MonitorResize="true" AutoWidth="true"
                    AutoExpandColumn="GhiChu" StripeRows="true">
                    <ColumnModel ID="ColumnModel1" runat="server">
                        <Columns>
                            <ext:CommandColumn Width="40" ColumnID="Command" Locked="true">
                                <Commands>
                                    <ext:GridCommand>
                                        <Menu>
                                            <Items>
                                                <ext:MenuCommand Text="Sửa " CommandName="Edit" Icon="ApplicationEdit" />
                                                <ext:MenuCommand Text="Xóa" CommandName="Delete" Icon="Delete" Cls="menuItemTop" />
                                            </Items>
                                        </Menu>
                                    </ext:GridCommand>
                                </Commands>
                            </ext:CommandColumn>
                            <ext:Column Header="Số nhà" DataIndex="SoNha" Width="70" />
                            <ext:Column Header="Thôn phố" DataIndex="ThonPho" Width="100" />
                            <ext:Column Header="Xã phường" DataIndex="XaPhuongName" Width="150" />
                            <ext:Column Header="Quận Huyện" DataIndex="QuanName" Width="150" />
                            <ext:Column Header="Tỉnh" DataIndex="TinhName" Width="150" />
                            <ext:Column Header="Ghi chú" DataIndex="GhiChu" />
                        </Columns>
                    </ColumnModel>
                    <BottomBar>
                        <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageIndex="1" PageSize="20"
                            HideRefresh="true">
                        </ext:PagingToolbar>
                    </BottomBar>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                    </SelectionModel>
                    <Listeners>
                        <Command Handler=" if(command=='Delete'){ConfirmDeleteDiaChi(record.id);}
                        else if(command=='Edit' && record!=null)
                        { Ext.net.Mask.show();#{DirectMethods}.DialogDiaChi('Edit',record.id);}
                        else{Ext.MessageBox.alert('Thông báo', 'Địa chỉ này không tồn tại.');}
                        " />
                    </Listeners>
                    <Store>
                        <ext:Store ID="storeDiachi" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="DiaChiID">
                                    <Fields>
                                        <ext:RecordField Name="DiaChiID" />
                                        <ext:RecordField Name="SoNha" />
                                        <ext:RecordField Name="ThonPho" />
                                        <ext:RecordField Name="XaPhuong" />
                                        <ext:RecordField Name="QuanHuyenID" />
                                        <ext:RecordField Name="TinhTPID" />
                                        <ext:RecordField Name="GhiChu" />
                                        <ext:RecordField Name="TinhName" />
                                        <ext:RecordField Name="QuanName" />
                                        <ext:RecordField Name="XaPhuongName" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                </ext:GridPanel>
            </Items>
        </ext:Panel>
    </Content>
    <Buttons>
        <ext:Button ID="BtnSelect" runat="server" Text="Chọn địa chỉ" Icon="Tick">
            <Listeners>
                <Click Handler="
                        var record=#{grdDiaChi}.selModel.getSelected();if(record!=null) {InsertEntity(record.data.DiaChiID,
               record.data.SoNha  + ' - ' +  record.data.ThonPho + ' - ' +  record.data.XaPhuongName+' - '+record.data.QuanName+' - '+record.data.TinhName); #{wdDiaChi}.hide();
              }else{Ext.MessageBox.alert('Thông báo', 'Vui lòng chon địa chỉ.');}" />
            </Listeners>
        </ext:Button>
        <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
            <Listeners>
                <Click Handler="#{wdDiaChi}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
<uc:UCDiaChi ID="UCDiaChi" runat="server"></uc:UCDiaChi>
